package com.xmb.wechat.delegate;

import android.content.Context;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.widget.ImageView;

import com.blankj.utilcode.util.ScreenUtils;
import com.blankj.utilcode.util.SizeUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.squareup.picasso.Picasso;
import com.xmb.wechat.R;
import com.xmb.wechat.baserecyclerview.BaseRecyclerViewManager;
import com.xmb.wechat.bean.PYQPicBean;
import com.xmb.wechat.picasso.PicassoPYQPicTransform;

import java.util.ArrayList;

/**
 * @Author lijiangop
 * @CreateTime 2020/5/9 17:42
 */
public class PYQPicDelegate extends BaseRecyclerViewManager {

    private int mItemWidth;

    public PYQPicDelegate(Context context, RecyclerView recyclerView) {
        super(context, recyclerView);
        mItemWidth = (ScreenUtils.getScreenWidth() - SizeUtils.dp2px(30) - SizeUtils.dp2px(10)) / 3;//宽-recyclerView的padding-itemDecoration
    }

    @Override
    public BaseQuickAdapter initAdapter() {
        return new BaseQuickAdapter<PYQPicBean, BaseViewHolder>(R.layout.item_pyq_publish_pic, new ArrayList()) {
            @Override
            protected void convert(BaseViewHolder helper, PYQPicBean item) {
                if (TextUtils.isEmpty(item.getPic()))
                    return;
                ImageView imageView = helper.getView(R.id.iv_pic);
                Picasso.get().load("file://" + item.getPic()).error(R.drawable.default_image)
                        .transform(new PicassoPYQPicTransform(mItemWidth))
                        .into(imageView);
            }
        };
    }

    @Override
    protected RecyclerView.LayoutManager getLayoutManager() {
        return new GridLayoutManager(context, 3);
    }

    @Override
    protected RecyclerView.ItemDecoration getItenDecoration() {
        return null;
    }
}
